					<h3 style="margin: 0px;"><i class="icon-dashboard"></i> SIP Servlets Server Settings</h3>
					<hr style="margin: 10 0px;"/>

					<button id="apply-server-settings" class="btn btn-small" onclick="applyServerSettings()"><i class="icon-save" style="color: #000000;"></i>  Apply Changes</button>
					
					<p>
						<br/>
					</p> 
					
					<div class="alert alert-error" id="login-settings-error" style="display:none;">
					  <button type="button" class="close">&times;</button>
					  Some Fields are not correctly filled out, please double check the settings below !
					</div>
					
 				
					
					<ul class="nav nav-tabs" id="myTab">
  						<li class="active"><a href="#congestion" data-toggle="tab">Congestion Control</a></li>
  						<li><a href="#timers" data-toggle="tab">SIP Timers</a></li>
						<li><a href="#various" data-toggle="tab">Various</a></li>
					</ul>	
						
  				 	<div class="tab-content">
						<div class="tab-pane active" id="congestion">
							<div class="control-group">								
								<label class="control-label">Congestion Control Checking Interval : </label><div class="controls"><input id="congestionControlCheckingInterval" type="text" class="input-large" placeholder="Congestion Control Checking Interval"></input></div>
							</div>
							<div class="control-group">
								<label class="control-label">Memory Threshold : </label><div class="controls"><input id="memoryThreshold" type="text" class="input-large" placeholder="Memory Threshold"></input></div>
							</div>
							<div class="control-group">
								<label class="control-label">Back To Normal Memory Threshold : </label><div class="controls"><input id="backToNormalMemoryThreshold" type="text" class="input-large" placeholder="Back To Normal Memory Threshold"></input></div>
							</div>
							<div class="control-group">
								<label class="control-label">Congestion Control Policy : </label><div class="controls"><select id="congestionControlPolicy" class="input-large">
									<option value="DropMessage">DropMessage</option>
			  						<option value="ErrorResponse">ErrorResponse</option>  					
								</select></div>
							</div>
					  	</div>
					  	<div class="tab-pane" id="timers">
					  		<div class="control-group">	
					  			<label class="control-label">SIP Base Timer Interval : </label><div class="controls"><input id="sipBaseTimer" type="text" class="input-large" placeholder="SIP Base Timer Interval"></input></div>
					  		</div>
					  		<div class="control-group">	
								<label class="control-label">SIP Timer T2 : </label><div class="controls"><input id="sipTimerT2" type="text" class="input-large" placeholder="SIP Timer T2"></input></div>
							</div>
							<div class="control-group">	
								<label class="control-label">SIP Timer T4 : </label><div class="controls"><input id="sipTimerT4" type="text" class="input-large" placeholder="SIP Timer T4"></input></div>
							</div>
							<div class="control-group">	
								<label class="control-label">SIP Timer Timer D : </label><div class="controls"><input id="sipTimerD" type="text" class="input-large" placeholder="SIP Timer D"></input></div>
							</div>
					 	</div>
					  	<div class="tab-pane" id="various">
					  		<div class="control-group">	
								<label class="control-label">Concurrency Control Mode : </label><div class="controls"><select id="concurrencyControlMode" class="input-large">
									<option value="None">None</option>
									<option value="SipSession">SipSession</option>
									<option value="SipApplicationSession">SipApplicationSession</option>  						  						  					
								</select></div>
							</div>
							<!--label>Logging Mode : </label><select id="loggingMode" type="text" class="input-large" placeholder="Logging Mode">
								<option value="trace">trace</option>
		  						<option value="debug">debug</option>
		  						<option value="default">default</option>
		  						<option value="production">production</option>
							</select>		<br/><br/>-->												  
					  	</div>					  
					</div>					
				 
				<script type="text/javascript">
					$('#login-settings-error .close').on("click", function(e) {
					    $(this).parent().hide();
					});
				
					$(document).ready(function () {												
						mbeanSearch="*:type=SipApplicationDispatcher";
						var mbean;
						$.ajax({
							dataType: "json",
							url: window.jolokiaProtocol + window.jolokiaAddress + ":" + window.jolokiaPort + "/jolokia/search/" + mbeanSearch
						})
						.done(function(html) {
							if (html.error) {
								logToConsole("ERROR", html.error);
							}
							else {			
								mbean = html.value[0];
								var j4p = new Jolokia({url: window.jolokiaProtocol + window.jolokiaAddress + ":" + window.jolokiaPort + "/jolokia/" });
								var baseTimerInterval = j4p.getAttribute(mbean, "BaseTimerInterval",{method: "post"});
								var t2Interval = j4p.getAttribute(mbean, "T2Interval",{method: "post"});
								var t4Interval = j4p.getAttribute(mbean, "T4Interval",{method: "post"});
								var timerDInterval = j4p.getAttribute(mbean, "TimerDInterval",{method: "post"});								
								var concurrencyControlMode = j4p.getAttribute(mbean, "ConcurrencyControlMode",{method: "post"});
								var congestionControlPolicyByName = j4p.getAttribute(mbean, "CongestionControlPolicyByName",{method: "post"});
								var congestionControlCheckingInterval = j4p.getAttribute(mbean, "CongestionControlCheckingInterval",{method: "post"});
								var memoryThreshold = j4p.getAttribute(mbean, "MemoryThreshold",{method: "post"});
								var backToNormalMemoryThreshold = j4p.getAttribute(mbean, "BackToNormalMemoryThreshold",{method: "post"});
								$("#memoryThreshold").val(memoryThreshold);
								$("#backToNormalMemoryThreshold").val(backToNormalMemoryThreshold);
								$("#sipBaseTimer").val(baseTimerInterval);
								$("#sipTimerT2").val(t2Interval);
								$("#sipTimerT4").val(t4Interval);
								$("#sipTimerD").val(timerDInterval);
								$("#concurrencyControlMode").val(concurrencyControlMode);
								$("#congestionControlCheckingInterval").val(congestionControlCheckingInterval);
								$("#congestionControlPolicy").val(congestionControlPolicyByName);
								
							}
						})
						.fail(function() {
							logToConsole("ERROR", "Failure trying to communicate with the SIP Servlets Server. Please try again later.");
						})
	    			});
					
					function applyServerSettings() {
						var formInvalid = false;
						var baseTimerInterval = $("#sipBaseTimer").val();
						if(baseTimerInterval.trim() == "") {
			    			$("#sipBaseTimer").addClass("required");					    			
			    			formInvalid = true;
			    		} else if($("#sipBaseTimer").hasClass("required")) {
			    			$("#sipBaseTimer").removeClass("required");		
			    		}
						var t2Interval = $("#sipTimerT2").val();
						if(t2Interval.trim() == "") {
			    			$("#sipTimerT2").addClass("required");					    			
			    			formInvalid = true;
			    		} else if($("#sipTimerT2").hasClass("required")) {
			    			$("#sipTimerT2").removeClass("required");		
			    		}
						var t4Interval = $("#sipTimerT4").val();
						if(t4Interval.trim() == "") {
			    			$("#sipTimerT4").addClass("required");					    			
			    			formInvalid = true;
			    		} else if($("#sipTimerT4").hasClass("required")) {
			    			$("#sipTimerT4").removeClass("required");		
			    		}
						var timerDInterval = $("#sipTimerD").val();
						if(timerDInterval.trim() == "") {
			    			$("#sipTimerD").addClass("required");					    			
			    			formInvalid = true;
			    		} else if($("#sipTimerD").hasClass("required")) {
			    			$("#sipTimerD").removeClass("required");		
			    		}										
						var congestionControlCheckingInterval = $("#congestionControlCheckingInterval").val();
						if(congestionControlCheckingInterval.trim() == "") {
			    			$("#congestionControlCheckingInterval").addClass("required");					    			
			    			formInvalid = true;
			    		} else if($("#congestionControlCheckingInterval").hasClass("required")) {
			    			$("#congestionControlCheckingInterval").removeClass("required");		
			    		}
						var memoryThreshold = $("#memoryThreshold").val();
						if(memoryThreshold.trim() == "") {
			    			$("#memoryThreshold").addClass("required");					    			
			    			formInvalid = true;
			    		} else if($("#memoryThreshold").hasClass("required")) {
			    			$("#memoryThreshold").removeClass("required");		
			    		}
						var backToNormalMemoryThreshold = $("#backToNormalMemoryThreshold").val();
						if(backToNormalMemoryThreshold.trim() == "") {
			    			$("#backToNormalMemoryThreshold").addClass("required");					    			
			    			formInvalid = true;
			    		} else if($("#backToNormalMemoryThreshold").hasClass("required")) {
			    			$("#backToNormalMemoryThreshold").removeClass("required");		
			    		}
						
						if(formInvalid) {
							$("#login-settings-error").show();
							logToConsole("ERROR", "Some Fields are not correctly filled out, please double check the settings !");
							return false;
						} else {
							$("#login-settings-error").hide();
						}
						
						mbeanSearch="*:type=SipApplicationDispatcher";
						var mbean;
						$.ajax({
							dataType: "json",
							url: window.jolokiaProtocol + window.jolokiaAddress + ":" + window.jolokiaPort + "/jolokia/search/" + mbeanSearch
						})
						.done(function(html) {
							if (html.error) {
								logToConsole("ERROR", html.error);
							}
							else {			
								mbean = html.value[0];
								var j4p = new Jolokia({url: window.jolokiaProtocol + window.jolokiaAddress + ":" + window.jolokiaPort + "/jolokia/" });
								j4p.setAttribute(mbean, "BaseTimerInterval",baseTimerInterval,{method: "post"});
								j4p.setAttribute(mbean, "T2Interval",t2Interval,{method: "post"});
								j4p.setAttribute(mbean, "T4Interval",t4Interval,{method: "post"});
								j4p.setAttribute(mbean, "TimerDInterval",timerDInterval,{method: "post"});								
								j4p.setAttribute(mbean, "ConcurrencyControlMode",$("#concurrencyControlMode").val(),{method: "post"});
								j4p.setAttribute(mbean, "CongestionControlPolicyByName",$("#congestionControlPolicy").val(),{method: "post"});
								j4p.setAttribute(mbean, "CongestionControlCheckingInterval",congestionControlCheckingInterval,{method: "post"});
								j4p.setAttribute(mbean, "MemoryThreshold",memoryThreshold,{method: "post"});
								j4p.setAttribute(mbean, "BackToNormalMemoryThreshold",backToNormalMemoryThreshold,{method: "post"});								
								logToConsole("INFO", "SIP Servlets Settings successfully updated.");
							}
						})
						.fail(function() {
							logToConsole("ERROR", "Failure trying to communicate with the SIP Servlets Server. Please try again later.");
						})						
					}
					</script>
